package com.eliza.demo.fg

import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Button
import android.widget.ProgressBar
import android.widget.TextView
import androidx.lifecycle.ViewModelProvider
import androidx.navigation.Navigation
import com.eliza.demo.R
import com.eliza.demo.vm.UserVm
import com.eliza.library.tools.InfoTools

class S2Fragment : Fragment() {
    private lateinit var vm: UserVm
    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        var view = inflater.inflate(R.layout.fragment_s2, container, false)
        arguments?.getString("user")
        arguments?.getString("pwd")


        activity?.let {
            vm = ViewModelProvider(
                it,
                ViewModelProvider.AndroidViewModelFactory(it.application)
            ).get(UserVm::class.java)
            InfoTools.LogTools("TAG", vm.userData.value?.userName ?: "Null")
        }
        InfoTools.LogTools("S2", vm.userData.value?.userName ?: "Null")
        InfoTools.LogTools("S2", vm.userData.value?.userAge ?: "Null")

        val s2DataHolder = S2DataHolder(view)
        s2DataHolder.pwd.text = (vm.userData.value?.userAge ?: "Null").toString()
        s2DataHolder.user.text = vm.userData.value?.userName ?: "Null"
        s2DataHolder.btn.setOnClickListener {
            Navigation.findNavController(view).navigate(R.id.action_s2Fragment_to_s3Fragment)
            s2DataHolder.pg_harm.progress = 34
            s2DataHolder.pg_life.progress = 12
            s2DataHolder.pg_speed.progress = 96
        }
        return view
    }

    inner class S2DataHolder(view: View) {
        var user: TextView = view.findViewById<TextView>(R.id.s2_tv_user)
        var pwd: TextView = view.findViewById<TextView>(R.id.s2_tv_pwd)
        var btn: Button = view.findViewById<Button>(R.id.s2_btn_buyIt)
        var pg_life: ProgressBar = view.findViewById<ProgressBar>(R.id.s2_pg_life)
        var pg_harm: ProgressBar = view.findViewById<ProgressBar>(R.id.s2_pg_harm)
        var pg_speed: ProgressBar = view.findViewById<ProgressBar>(R.id.s2_pg_speed)
    }
}